package com.example.qq.config;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.alibaba.android.arouter.launcher.ARouter;
import com.apkfuns.logutils.LogUtils;
import com.example.qq.R;

public abstract class BaseActivity<T extends ViewDataBinding>  extends AppCompatActivity {

    FrameLayout frameLayout;
    protected T mBinding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base);
        setMode();
        ARouter.getInstance().inject(this);
        LogUtils.e(getClass().getSimpleName());

        frameLayout=findViewById(R.id.frameLayout);
        frameLayout.removeAllViews();
        frameLayout.addView(LayoutInflater.from(this).inflate(fillLayout(), null,false));
        mBinding= DataBindingUtil.inflate(getLayoutInflater(),fillLayout(),frameLayout,true);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityCollector.removeActvity(this);
    }

    protected abstract int fillLayout();

    /**
     * 设置沉浸式主题界面
     */
    private void setMode() {
        //获取到当前界面的decorView
        View decorView = getWindow().getDecorView();
        int option = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
        getWindow().setStatusBarColor(getResources().getColor(R.color.color_01bbff));
        //设置UI可见性参数
        decorView.setSystemUiVisibility(option);
        //将actionBar也隐藏
        ActionBar actionBar = getSupportActionBar();
        actionBar.hide();
    }
}